<?php
/**
 * Created by PhpStorm.
 * User: wg
 * Date: 16/4/26
 * Time: 9:50
 */

namespace C\mod{

    use C\lib\Db;
    use C\lib\Sql;

    class sack extends mod{

        protected static $__table_s = 'sack';
        protected static $__primary_s = 'id';

        public static function groupBy($workerId,$parameter,$sackIds) {
            $list = [];
            $sql = new Sql();
            if(count($sackIds)>0) {
                $sql->select($parameter . ', COUNT(0) AS count', static::$__table_s)->where([['id', 'in', $sackIds], 'worker_id' => $workerId, 'is_finish' => '0'])->groupBy($parameter);
            } else {
                $sql->select($parameter . ', COUNT(0) AS count', static::$__table_s)->append(' WHERE worker_id=' . $workerId . ' AND is_finish=0')->groupBy($parameter);
            }
            \C\log($sql->sql);
            if ($ps = Db::query($sql->sql)) {
                while ($o = $ps->fetchObject(static::class))
                    $list[] = $o;
            }
            return $list;
        }

    }

}

